package main

import (
	"fmt"
	"math"
	"strings"
)

func BinaryFormat(n int32) string {
	a := uint32(n)
	sb := strings.Builder{}
	c := uint32(math.Pow(2, 31))
	fmt.Println("a:", a)
	fmt.Printf("sb is %s\n", sb)
	fmt.Println("c:", c)

	for i := 0; i < 32; i++ {
		if a&c != 0 { //if后面需要填空
			sb.WriteString("1")

		} else {
			sb.WriteString("0")
		}
		fmt.Println("运算后的a:", a)
		c >>= 1 //这里需要填空
		fmt.Println("右移后的c:", c)
	}
	fmt.Println(sb.String())
	return sb.String()

}

func main() {

	BinaryFormat(1) //00000000000000000000000000000001
	// BinaryFormat(2) //00000000000000000000000000000010
	// BinaryFormat(3)
}
